	//make pages visible
function drawpages(currentPage, maxPage) {
	var firstpage = 1;
	var prepage = currentPage - 1;
	var nextpage = currentPage + 1;
//	var divPage = document.getElementById("nav-page");
//	divPage.innerHTML="<li><a href='#'><</a></li>";

	if(currentPage < 1) {
		currentPage = 1;
	}
	if(maxPage < 1) {
		maxPage = 1;
	}
	if(currentPage > maxPage) {
		currentPage = maxPage;
	}
		
	if(currentPage == 1 && maxPage == 1) {
		disablePageComponent();
	}
		
	$("#grid-pager_center .ui-pg-input").val(currentPage);
}

function disablePageComponent() {
	$("#first_grid-pager").unbind();
	$("#prev_grid-pager").unbind();
	$("#next_grid-pager").unbind();
	$("#last_grid_pager").unbind();
	$(".ui-pg-selbox").unbind();
}

//click event
function pageClick(pageUrl, pageTable, pageData, pageSize) {
	pageSize = parseInt(pageSize);
	var currentPage = parseInt(pageData.page.page);
	var NextPage = currentPage + 1;
	var PrePage = currentPage - 1;
	
//	$.cookie('currentPage', currentPage);			// for what?
	
	$("#first_grid-pager").unbind().click(function() {
		pageData.page.page = 1;
		
		if("bookTable" == pageTable) {
			showBook(pageUrl, pageData);
		}
	});
	
	$("#prev_grid-pager").unbind().click(function() {
		if(PrePage < 1) {
			currentPage = 1;
		} else {
			currentPage = PrePage;
		}
		
		pageData.page.page = currentPage;
		
		if("bookTable" == pageTable) {
			showBook(pageUrl, pageData);
		}
	});
	
	$("#next_grid-pager").unbind().click(function() {
		if(NextPage > pageSize) {
			currentPage = pageSize;
		} else {
			currentPage = NextPage;
		}
		
		pageData.page.page = currentPage;
		
		if("bookTable" == pageTable) {
			showBook(pageUrl, pageData);
		}
	});
	
	$("#last_grid-pager").unbind().click(function() {
		pageData.page.page = pageSize;
		
		if("bookTable" == pageTable) {
			showBook(pageUrl, pageData);
		}
	});
	
	
	//go to selected page
	$("#grid-pager_center .ui-pg-input").blur(function(){
		gotoPage();
	});
	
	$("#grid-pager_center .ui-pg-input").unbind().bind('keypress', function(event) {
		if(event.keyCode == "13") {
			gotoPage();
		}
	});
	
	function gotoPage() {
		var content = $("#grid-pager_center .ui-pg-input").val();
		if (content < 1) {
			content = 1;
			$("#grid-pager_center .ui-pg-input").val(content);
		} else if (content > pageSize) {
			content = pageSize;
			$("#grid-pager_center .ui-pg-input").val(content);
		}
		
		pageData.page.page = content;
		
		if("bookTable" == pageTable) {
			showBook(pageUrl, pageData);
		}
	}
}